package com.app.OOS.mapper;

import java.util.List;



import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hibernate.annotations.Parent;

import com.app.OOS.domain.Batch;
import com.app.OOS.domain.Batch_courseware;
import com.app.OOS.domain.Course;
import com.app.OOS.domain.Course_Courseware;
import com.app.OOS.domain.Courseware;
import com.app.OOS.domain.Record;
import com.app.OOS.domain.Score;
import com.app.OOS.domain.User;
import com.app.OOS.domain.User_batch;
import com.app.OOS.domain.User_courseware_batch;




@Mapper
public interface AdminMapper {
	//审核学员
	@Select("select * from user where type=0 and setting=0 limit #{tmp},#{limit}")
	public List<User> selectUsers(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from user where type=0 and setting=0")
	public int tol();
	
	//通过学员
	@Update("update user set setting=1 where userId=#{userId}")
	public void updateUsers(@Param("userId")int userId);
	
	//不通过学员
	@Delete("delete from user where userId=#{userId}")
	public void deleteUsers(@Param("userId")int userId);
	
	//课程管理
	@Select("select * from course limit #{tmp},#{limit}")
	public List<Course> selectCourse(@Param("tmp")int tmp,@Param("limit")int limit);
	
	@Select("select count(*) from course")
	public int tol2();
	
	//删除课程
	@Select("delete from course where courseId=#{courseId}")
	public void deleteCourse(@Param("courseId")int courseId);
	
	//查询所有课程
	@Select("select * from course")
	public List<Course> selectCourses();
	
	//更新课程
	@Update("update course set courseName=#{courseName} where courseId=#{courseId}")
	public void updateCourse(@Param("courseName")String courseName,@Param("courseId")int courseId);
	
	//新增课程
	@Insert("insert into course(courseId,courseName) values(#{courseId},#{courseName})")
	public void insertCourse(@Param("courseId")int courseId,@Param("courseName")String courseName);
	
	//查询批次
	@Select("select * from batch limit #{tmp},#{limit}")
	public List<Batch> selectBatch(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from batch")
	public int tol3();
		
	//删除批次
	@Delete("delete from batch where batchId=#{batchId}")
	public void deleteBatch(@Param("batchId")int batchId);
	
	//更新批次
	@Update("update batch set batchName=#{batchName} where batchId=#{batchId}")
	public void updateBatch(@Param("batchName")String batchName,@Param("batchId")int batchId);
	
	//查询所有批次
	@Select("select * from batch")
	public List<Batch> selectBatchs();
	
	//新增课程（插入）
	@Insert("insert into batch(batchId,batchName) values(#{batchId},#{batchName})")
	public void insertBatch(@Param("batchId")int batchId,@Param("batchName")String batchName);

	//查询课件表
	@Select("select * from course c,courseware cw where cw.courseId=c.courseId limit #{tmp},#{limit}")
	public List<Course_Courseware> selectCourseWare(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from courseware")
	public int tol4();
	

	//查询所有课件
	@Select("select * from courseware")
	public List<Courseware> selectCourseWares();
	//删除课件
	@Delete("delete from courseware where coursewareId=#{coursewareId}")
	public void deleteCourseWare(@Param("coursewareId")int coursewareId);
	
	//修改课件
	@Update("update courseware set coursewareName=#{coursewareName},courseId=#{courseId} where coursewareId=#{coursewareId}")
	public void updateCourseWare(@Param("coursewareName")String coursewareName,@Param("courseId")int courseId,@Param("coursewareId")int coursewareId);

	//增加课件
	@Insert("insert into courseware(coursewareId,coursewareName,courseId,cwPeriod,coursewareSrc) values(#{coursewareId},#{coursewareName},#{courseId},#{cwPeriod},#{src})")
	public void insertCourseware(@Param("coursewareId")int coursewareId,@Param("coursewareName")String coursewareName,@Param("courseId")int courseId,@Param("cwPeriod")int cwPeriod,@Param("src")String src);

	//查询 批次-课件 带参数
	@Select("select * from batch_courseware bc,batch b,courseware c where bc.batchId=b.batchId and bc.coursewareId=c.coursewareId limit #{tmp},#{limit}")
	public List<Batch_courseware> selectBatchCourseWare(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from batch_courseware")
	public int tol5();
	//查询批次-课件，不带参数
	@Select("select count(*) from batch_courseware bc where bc.batchId=#{batchId} and bc.coursewareId=#{coursewareId}")
	public int selectBatchCourseWares(@Param("batchId")int batchId,@Param("coursewareId")int coursewareId);
	@Select("select count(*) from batch_courseware bc where bc.batch_courseware_id=#{batch_courseware_id}")
	public int selectBatchCourseWaress(@Param("batch_courseware_id")int batch_courseware_id);
	
	//删除 批次-课件
	@Delete("delete from batch_courseware where batch_courseware_id=#{batch_courseware_id}")
	public void deleteBatchCourseWare(@Param("batch_courseware_id")int batch_courseware_id);
	
	//更新 批次-课件
	@Update("update batch_courseware set batchId=#{batchId},coursewareId=#{coursewareId} where batch_courseware_id=#{batch_courseware_id}")
	public void updateBatchCourseWare(@Param("batchId")int batchId,@Param("coursewareId")int coursewareId,@Param("batch_courseware_id")int batch_courseware_id);
	
	//新增 批次-课件
	@Insert("insert into batch_courseware(batchId,coursewareId,batch_courseware_id) values(#{batchId},#{coursewareId},#{batch_courseware_id})")
	public void insertBatchCourseWare(@Param("batchId")int batchId,@Param("coursewareId")int coursewareId,@Param("batch_courseware_id")int batch_courseware_id);
	
	
	//查询学员-批次
	@Select("select * from user_batch ub,user u,batch b where ub.batchId=b.batchId and ub.userId=u.userId limit #{tmp},#{limit}")
	public List<User_batch> selectUserBatch(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from user_batch")
	public int tol6();
	
	//查询学员  不带参数
	@Select("select * from user where type=0 and setting=1")
	public List<User> selectUseres();
	
	//删除 学员-批次
	@Delete("delete from user_batch where user_batch_id=#{user_batch_id}")
	public void deleteUserBatch(@Param("user_batch_id")int user_batch_id); 
		
	//更新学员-批次
	@Update("update user_batch set batchId=#{batchId} where user_batch_id=#{user_batch_id}")
	public void updateUserBatch(@Param("user_batch_id")int user_batch_id,@Param("batchId")int batchId);

	//查询是否有相同的数据
	@Select("select count(*) from user_batch where userId=#{userId} and batchId=#{batchId}")
	public int selectUserBatchSS(@Param("userId")int userId,@Param("batchId")int batchId);
	
	//查询userId
	@Select("select count(*) from user_batch where user_batch_id=#{user_batch_id}")
	public int SelectA(@Param("user_batch_id")int user_batch_id);
	//插入学员-批次
	@Insert("insert into user_batch(user_batch_id,userId,batchId) values(#{user_batch_id},#{userId},#{batchId})")
	public void insertUserBatch(@Param("user_batch_id")int user_batch_id,@Param("userId")int userId,@Param("batchId")int batchId);

	//查询学生成绩
	@Select("select * from score limit #{tmp},#{limit}")
	public List<Score> selectScore(@Param("tmp")int tmp,@Param("limit")int limit);
	@Select("select count(*) from score")
	public int tol7();

	//更新课件时间
	@Select("update courseware set Ctime=#{Ctime} where coursewareId=#{coursewareId}")
	public void updateCtime(@Param("Ctime")int Ctime,@Param("coursewareId")int coursewareId);

	
	@Select("select * from record r,batch b,courseware c where r.batchId=b.batchId and r.coursewareId=c.coursewareId")
	public List<User_courseware_batch> selectRR();
}
